﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace AllenalaMente.Games.Quake
{
    public partial class Rock : UserControl
    {
        public EventHandler rockPopped;
        public int velocity, height;
        public bool destroied = false;
        private DispatcherTimer updateTimer;

        public Rock()
        {
            InitializeComponent();

            rock.Width = 0;
            rock.Height = 0;
            //points.Visibility = Visibility.Collapsed;


            // Update timer
            updateTimer = new DispatcherTimer();
            updateTimer.Interval = TimeSpan.FromMilliseconds(70);
            updateTimer.Tick += new EventHandler(updateTimer_Tick);
            updateTimer.Start();

        }

        private void updateTimer_Tick(object sender, EventArgs e)
        {
            if ((rock.Width < 80) && (rock.Height < 80))
            {
                rock.Width += 2;
                rock.Height += 2;
            }

            
        }

        public void popFade()
        {
            destroied = true;
            //points.Visibility = Visibility.Visible;
            //points.Text = "+5";
            

            Storyboard pointsAnimation = new Storyboard();
            pointsAnimation.Duration = TimeSpan.FromSeconds(0.3);

            DoubleAnimation textBlockOpacity = new DoubleAnimation();
            textBlockOpacity.Duration = pointsAnimation.Duration;
            textBlockOpacity.From = 1;
            textBlockOpacity.To = 0;
            pointsAnimation.Children.Add(textBlockOpacity);
            Storyboard.SetTarget(textBlockOpacity, this);
            Storyboard.SetTargetProperty(textBlockOpacity, new PropertyPath("(UIElement.Opacity)"));

            pointsAnimation.Begin();

            pointsAnimation.Completed += new EventHandler(fadeAnimation_Completed);
            
        }

        void fadeAnimation_Completed(object sender, EventArgs e)
        {
            if (rockPopped != null)
                rockPopped(this, null);
        }
    }
}
